import ActorUtil from "@/ActorUtil";
import MessageUtil from "@/MessageUtil";
import BaseUtil from "@/BaseUtil";

export default class SolarActorState {


    constructor() {

        this.initActorAbility()
        this.initActorItem()
        BaseUtil.runLater(2, () => {
            //延迟添加hook 以免被作者直接设置hook 给顶掉
            MessageUtil._sl_init_message_hook()
        })

    }


    initActorAbility() {
        se.onUnitSpellCast(e => {
            ActorUtil.ifHasActorAbility(e.spellAbilityIdStr, (actor) => {
                if (actor.isPassive() || actor.isDisable()) {
                    IssueImmediateOrder(e.trigUnit, "stop")
                    return
                }
                actor.action(e);
            })
        });
    }

    initActorItem() {

        se.onUnitPickupItem(e => {
            ActorUtil.ifHasActorItem(e.manipulatedItemTypeIdStr, (actor) => {
                actor.unit = e.trigUnit
                actor.refresh();
            })
        })
        se.onUnitDropItem(e => {
            ActorUtil.ifHasActorItem(e.manipulatedItemTypeIdStr, (actor) => {
                actor.unit = null;

            })
        })
        se.onUnitUseItem(e => {
            ActorUtil.ifHasActorItem(e.manipulatedItemTypeIdStr, (actor) => {
                if (actor.isPassive() || actor.isDisable()) {
                    return
                }
                actor.action(e);
            })
        })


    }


}